/*
* @Author: song
* @Description:震动动能
* @Date: 2024年04月18日 星期四 11:04:47
* @Modify:
*/

#if UNITY_IOS
using System.Runtime.InteropServices;
#endif
using UnityEngine;

namespace SCore.Function.Vibration
{
    public class SVibration
    {
#if UNITY_ANDROID
        private static AndroidJavaClass _unityPlayer;
        private static AndroidJavaObject _vibrator;
#endif
#if UNITY_IOS
        [DllImport("__Internal")]
        private static extern void SingleVibration(int adType);

        [DllImport("__Internal")]
        private static extern void ShakingVibration(int adType);

#endif


        public static void Vibrate(long time)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (_unityPlayer == null)
            {
                _unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                var currentActivity = _unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
                _vibrator = currentActivity.Call<AndroidJavaObject>("getSystemService", "vibrator");
            }

            if (_vibrator != null)
            {
                _vibrator.Call("vibrate", time);
            }
#endif
#if UNITY_IOS && !UNITY_EDITOR
            SingleVibration(2);
#endif
        }
    }
}